
var mapData = createMap();
var player = createEntity();

var update = function () {
	var canvas = document.getElementById("battlefieldCanvas");
	if (canvas.getContext) {
		
		var context = canvas.getContext("2d");
		context.setTransform(1, 0, 0, 1, 0, 0);

		context.clearRect(0, 0, canvas.width, canvas.height);
		context.translate(0, 0);
		
	    context.scale(0.5, 0.5);
		
		drawMap(context, mapData);
		drawEntity(context, player);
	}
};

setInterval(update, 100);

window.addEventListener('keydown', this.handleKeyboarEvent, false);

function handleKeyboarEvent(e) {
    var code = e.keyCode;
    switch (code) {
        case 37:
        	moveLeft(player);
        	break;
        case 38:
        	moveUp(player);
        	break;
        case 39:
        	moveRight(player);
        	break;
        case 40:
        	moveDown(player);
        	break;
        default:
    }
}